import path from 'path'
import os from 'os'
import fs from 'fs'

/**
 * 获取配置文件路径
 * @returns {string}
 */
function getResPath() {
    if (process.env.NODE_ENV === 'development') {
        return "./configData"
    } else {
        return process.resourcesPath + "/configData"
    }
}

export default {

    getConfigData(fileName,relativePath) {
        return new Promise((resolve, reject) => {
            //目录路径
            const basePath = relativePath ? getResPath() + '/' + relativePath : getResPath();
            const file_path = path.join(basePath, fileName).replace(/\\/g, "\/");
            //读取json文件
            fs.readFile(file_path, 'utf-8', function(err, data) {
                if (err) {
                    reject('文件读取失败');
                } else {
                    resolve(data);
                }
            });
        })
    }

}
